package org.dromara.test;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import java.util.Date;

public class Temp {
    public static void main(String[] args) {
        String dateStr = DateTime.now().toString(DatePattern.PURE_DATE_PATTERN);
        Date now = new Date();
        Date targetDate = DateUtil.truncate(now, DateField.DAY_OF_WEEK);
        String start = DateUtil.offsetDay(targetDate, -5).toString(DatePattern.NORM_DATETIME_PATTERN);
        String end = DateUtil.offsetDay(targetDate, -4).toString(DatePattern.NORM_DATETIME_PATTERN);
        String detailSQL = """
            SUBMIT /*+set_var(query_timeout=100000)*/ TASK monitor_point_data{date}_async AS
            INSERT into monitor_point_data
            SELECT monitor_point_id, DATE_ADD(happen_time, INTERVAL 5 DAY) AS happen_time, num_value, value, id FROM monitor_point_data where happen_time >= '{start}' and happen_time < '{end}'
            """;
        String minuteSQL = """
            SUBMIT TASK monitor_point_data_minute{date}_async AS
            INSERT into monitor_point_data_minute
            SELECT monitor_point_id, DATE_ADD(happen_time, INTERVAL 5 DAY) AS happen_time, num_value, sum_val, min_val, max_val, id FROM monitor_point_data_minute where happen_time >= '{start}' and happen_time < '{end}'
            """;

        String hourSQL = """
            SUBMIT TASK monitor_point_data_hour{date}_async AS
            INSERT into monitor_point_data_hour
            SELECT monitor_point_id, DATE_ADD(happen_time, INTERVAL 5 DAY) AS happen_time, num_value, sum_val, min_val, max_val, id FROM monitor_point_data_hour where happen_time >= '{start}' and happen_time < '{end}'
            """;

        detailSQL = detailSQL.replace("{date}", dateStr).replace("{start}", start).replace("{end}", end);
        minuteSQL = minuteSQL.replace("{date}", dateStr).replace("{start}", start).replace("{end}", end);
        hourSQL = hourSQL.replace("{date}", dateStr).replace("{start}", start).replace("{end}", end);

        System.out.println(detailSQL);
        System.out.println(minuteSQL);
        System.out.println(hourSQL);
    }
}
